<template>
  <div>
    <Description @register="orderRegister" class="enter-y" />
    <!-- <Description @register="retailRegister" class="my-4 enter-y" /> -->
  </div>
</template>

<script lang="ts" setup>
  import { OrderDetail } from '@/api/membership';
  import { Description, DescItem, useDescription } from '@/components/Description/index';
  import { ref } from 'vue';
  import { useRoute } from 'vue-router';
  import Dictionary from '@/utils/dictionary';

  const route = useRoute();
  const dicts = Dictionary.getLocalMulti(['orderState', 'orderType', 'payType', 'payMode']);

  async function getOrderDetail() {
    let res = await OrderDetail(route.query.id);
    console.log('res--->', res);
    Object.keys(orderData.value).forEach((k) => {
      if (k === 'orderType') {
        orderData.value[k] = dicts.orderType.find((v) => v.dictValue == res[k])?.dictLabel as any;
      } else if (k === 'payMode') {
        orderData.value[k] = dicts.payMode.find((v) => v.dictValue == res[k])?.dictLabel as any;
      } else {
        orderData.value[k] = res[k];
      }
    });
  }

  getOrderDetail();

  const orderSchema: DescItem[] = [
    {
      label: '订单编号',
      field: 'orderCode',
    },
    {
      label: '实付金额',
      field: 'payMoney',
    },
    {
      label: '订单类型',
      field: 'orderType',
    },
    {
      label: '提交时间',
      field: 'createTime',
    },
    {
      label: '支付方式',
      field: 'payMode',
    },
    {
      label: '支付流水号',
      field: 'payCode',
    },
    {
      label: '支付时间',
      field: 'payTime',
    },
  ];

  const orderData = ref({
    orderCode: undefined,
    payMoney: undefined,
    orderType: undefined,
    createTime: undefined,
    payMode: undefined,
    payCode: undefined,
    payTime: undefined,
  });

  const [orderRegister] = useDescription({
    title: '订单详情',
    data: orderData,
    schema: orderSchema,
    column: 2,
  });

  // const retailSchema: DescItem[] = [
  //   {
  //     label: '供应商',
  //     field: 'orderCode',
  //   },
  //   {
  //     label: '分销商',
  //     field: 'payMoney',
  //   },
  //   {
  //     label: '分账总额',
  //     field: 'orderType',
  //   },
  //   {
  //     label: '分账比例',
  //     field: 'createTime',
  //   },
  //   {
  //     label: '分账状态',
  //     field: 'payMode',
  //   },
  // ];

  // const retailData = {
  //   orderCode: 'MO2236219425',
  //   payMoney: 0.01,
  //   orderType: 'MEMBER_FEES',
  //   createTime: '2022-12-28 09:49:16',
  //   payMode: 'xx',
  //   payTime: '2022-12-28 09:49:16',
  // };

  // const [retailRegister] = useDescription({
  //   title: '分销详情',
  //   data: retailData,
  //   schema: retailSchema,
  //   column: 2,
  // });
</script>

<style scoped></style>
